using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using NLog;

namespace GameShow.DAL
{
    public class Player02DAL : DALBase
    {
        private static Logger log = LogManager.GetCurrentClassLogger();

        public void InsertResult(int TeamId, int QuestionId, int AnsId, int Value, int Mark, float AnsTime, int ResultType, int BussinessType)
        {
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "INSERT INTO tblResult(TeamId, QuestionId, AnsId, Value, Mark, AnsTime, ResultType, UpdateTime, BussinessType) " +
                                                    "VALUES (@TeamId, @QuestionId, @AnsId, @Value, @Mark, @AnsTime, @ResultType, getdate(), @BussinessType)";

                command.Parameters.Add(new SqlParameter("TeamId", TeamId));
                command.Parameters.Add(new SqlParameter("QuestionId", QuestionId));
                command.Parameters.Add(new SqlParameter("AnsId", AnsId));
                command.Parameters.Add(new SqlParameter("Value", Value));
                command.Parameters.Add(new SqlParameter("Mark", Mark));
                command.Parameters.Add(new SqlParameter("AnsTime", AnsTime));
                command.Parameters.Add(new SqlParameter("ResultType", ResultType));
                command.Parameters.Add(new SqlParameter("BussinessType", BussinessType));

                command.Connection = AppConnection;
                command.ExecuteNonQuery();
               
            }
            catch (Exception ex)
            {
                log.ErrorException(string.Empty, ex);
            }
            finally
            {
                AppConnection.Close();
            }
        }

        //CuongBM: 26-May-2012
        //Update cau tra loi, cho truong hop nguoi choi chon lai cau tra loi
        public void UpdateResult(int TeamId, int QuestionId, int AnsId, int Value, int Mark, float AnsTime, int ResultType, int BussinessType)
        {
            SqlCommand command = new SqlCommand();
            try
            {
                command.CommandText = "UPDATE tblResult " +
                                      "SET AnsId = @AnsId," +
                                          "Value = @Value," +
                                          "Mark = @Mark," +
                                          "AnsTime = @AnsTime," +
                                          "ResultType = @ResultType," +
                                          "UpdateTime = getdate()," +
                                          "BussinessType = @BussinessType" +
                                       " WHERE " +
                                               "TeamId = @TeamId  AND " +
                                               "QuestionId = @QuestionId ";

                command.Parameters.Add(new SqlParameter("AnsId", AnsId));
                command.Parameters.Add(new SqlParameter("Value", Value));
                command.Parameters.Add(new SqlParameter("Mark", Mark));
                command.Parameters.Add(new SqlParameter("AnsTime", AnsTime));
                command.Parameters.Add(new SqlParameter("ResultType", ResultType));
                command.Parameters.Add(new SqlParameter("BussinessType", BussinessType));
                command.Parameters.Add(new SqlParameter("TeamId", TeamId));
                command.Parameters.Add(new SqlParameter("QuestionId", QuestionId));

                command.Connection = AppConnection;
                command.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                log.ErrorException(string.Empty, ex);
            }
            finally
            {
                AppConnection.Close();
            }
        }


    }
}
